package cn.wolfcode.web.controller;


import cn.wolfcode.domain.ZmessageReply;
import cn.wolfcode.service.IZmessageReplyService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/zmessageReply")
public class ZmessageReplyController {

    @Autowired
    private IZmessageReplyService zmessageReplyService;


    @RequiredPermission(name="留言回复页面",expression="zmessageReply:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<ZmessageReply> pageInfo = zmessageReplyService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "zmessageReply/list";
    }


    @RequiredPermission(name="留言回复删除",expression="zmessageReply:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           zmessageReplyService.delete(id);
        }
        return "redirect:/zmessageReply/list";
    }


    @RequiredPermission(name="留言回复新增/编辑",expression="zmessageReply:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(ZmessageReply zmessageReply) {
        if (zmessageReply.getId() == null) {
            zmessageReplyService.save(zmessageReply);
        } else {
            zmessageReplyService.update(zmessageReply);
        }
        return "redirect:/zmessageReply/list";
    }


    @RequiredPermission(name="留言回复新增/编辑",expression="zmessageReply:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("zmessageReply",zmessageReplyService.get(id));
        }
        return "zmessageReply/input";
    }
}
